package calculator.operator.sp;


import calculator.operator.Operator;
import calculator.operator.Priority;

import java.util.Stack;

public class FactorialOperator implements Operator {


    public double doFact(double num){
        if (num == 1)
            return num;
        else
            return num * doFact(num - 1);
    }

    @Override
    public double doCal(Stack<Double> stack) {
        return doFact(stack.pop());
    }

    @Override
    public int getPriority() {
        return Priority.PRIORITY_MID + 1;
    }

    @Override
    public boolean support(char c) {
        return c == '!';
    }

    @Override
    public String toString() {
        return "!";
    }
}
